﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScriptEditor.Commands
{
    class Command_CharPath : Command
    {
        public string name
        {
            get
            {
                return Value1;
            }
            set
            {
                Value1 = value;
            }
        }
        public Vector3[] positions
        {
            get
            {
                string[] strs = Value2.Split(new char[] { ',' });
                Vector3[] time = new Vector3[strs.Length];
                for (int i = 0; i < strs.Length; i++)
                {
                    time[i] = StringToVector3(strs[i]);
                }
                return time;
            }
            set
            {
                Value2 = Vector3ToString(value[0]);
                for (int i = 1; i < value.Length; i++)
                {
                    Value2 += "," + Vector3ToString(value[i]);
                }
            }
        }
        public float duration
        {
            get
            {
                return float.TryParse(Value3, out float result) ? result : 0.5f;
            }
            set
            {
                Value3 = value.ToString();
            }
        }
        public PATH pathType
        {
            get
            {
                return (PATH)(int.TryParse(Value4, out int result) ? result : 0);
            }
            set
            {
                Value4 = ((int)value).ToString();
            }
        }
        public PathMode pathMode
        {
            get
            {
                return Enum.TryParse(Value5, out PathMode result) ? result : PathMode.Ignore;
            }
            set
            {
                Value5 = value.ToString();
            }
        }
        public int resolution
        {
            get
            {
                return int.TryParse(Value6, out int result) ? result : 5;
            }
            set
            {
                Value6 = value.ToString();
            }
        }
        public int loopCount
        {
            get
            {
                return int.TryParse(Value7, out int result) ? result : 1;
            }
            set
            {
                Value7 = value.ToString();
            }
        }
        public Loop loopType
        {
            get
            {
                return (Loop)(int.TryParse(Value8, out int result) ? result : 2);
            }
            set
            {
                Value8 = ((int)value).ToString();
            }
        }
        public Command_CharPath()
        {
            CommandType = COMMANDTYPE.CharPath;
            name = "请输入角色名";
            positions = new Vector3[] { new Vector3 { x = 0, y = 0, z = 0 } };
            duration = 0.5f;
            pathType = PATH.Linear;
            pathMode = PathMode.Ignore;
            resolution = 5;
            loopCount = 1;
            loopType = Loop.Incremental;
            Wait = true;
        }
        public Command_CharPath(string Name, Vector3[] Positions, float Durations , PATH PathType , PathMode PathMode, int Resolution, int LoopCount, Loop LoopType)
        {
            CommandType = COMMANDTYPE.CharPath;
            name = Name;
            positions = Positions;
            duration = Durations;
            pathType = PathType;
            pathMode = PathMode;
            resolution = Resolution;
            loopCount = LoopCount;
            loopType = LoopType;
            Wait = true;
        }
        public override string ToString()
        {
            string pos = "";
            foreach(Vector3 p in positions)
            {
                pos += Vector3ToString(p) + " ";
            }
            return CommandType.ToString() + ":\n" + "角色连续移动:" + name + "到" + pos;
        }
    }
}
